
const app = getApp()
Page({
  data: {
    type:"",
    boxTag:"",
    box_list:[],
    pageNum:1,
    totalPage:0
  },
  onLoad: function (options) {
    this.setData({
      boxTag:options.type=='新品预售'?'预售':options.type=='盲盒专区'?'盲盒':'热卖',
      type:options.type
    })
    wx.setNavigationBarTitle({
      title: options.type
    })
    this.getBoxList()
  },
  toDetail(e){
    if (this.data.type=="盲盒专区") {
      wx.navigateTo({
        url: '/pages/boxes/blind-boxes?id=' + e.currentTarget.dataset.id,
      })
    }else{
      let goodstype = this.data.type=='新品预售'?1:0
      wx.navigateTo({
        url: '/pages/market/market-detail/market-detail?id='+e.currentTarget.dataset.id+'&goodstype=' + goodstype,
      })
    }
  },
getBoxList(){
  let _this = this;
  let url = _this.data.type=="新品预售"?"api/mall/findPresell":_this.data.type=="盲盒专区"?"api/series/findLimit":"api/mall/findSales";
  let method = _this.data.type=="盲盒专区"?'post':'get'
  app.util.request({
      url: url,
      method: method,
      data: {
        status:1,
        page: _this.data.pageNum,
        pageSize:10,
      },
      success(response) {
          if (response.data.code == 0) {
              _this.setData({
                totalPage:response.data.data.pages,
                 box_list: [..._this.data.box_list,...response.data.data.list]
              })
          }
      }
  })
},
})
